<template>
  <div class="employees">
    <!-- 工具栏组件 -->
    <mytools>
      <template #right>
        <el-button size="mini" type="primary">导入</el-button>
        <el-button @click="openAdd" size="mini" type="primary"
          ><i class="el-icon-plus"></i>新增员工</el-button
        >
      </template>
    </mytools>
    <!-- 表格数据 -->
    <el-card class="mycard">
      <el-table :data="list">
        <el-table-column
          label="序号"
          type="index"
          fixed="left"
        ></el-table-column>
        <el-table-column
          label="姓名"
          width="200"
          prop="username"
        ></el-table-column>
        <el-table-column
          label="手机号"
          width="200"
          prop="mobile"
        ></el-table-column>
        <el-table-column
          label="工号"
          width="200"
          prop="workNumber"
        ></el-table-column>
        <el-table-column label="聘用形势" width="200" prop="formOfEmployment">
          <!-- 使用过滤器 -->
          <template slot-scope="{ row }">
            {{ row.formOfEmployment | myEmpolyees }}
          </template>
        </el-table-column>
        <el-table-column
          label="部门"
          width="200"
          prop="departmentName"
        ></el-table-column>
        <el-table-column
          label="入职时间"
          width="200"
          prop="timeOfEntry"
        ></el-table-column>
        <el-table-column label="是否在职" width="200"></el-table-column>
        <el-table-column label="状态" width="200" prop="name"></el-table-column>
        <el-table-column label="操作" width="300" fixed="right">
          <template>
            <el-button type="text">查看</el-button>
            <el-button type="text">转正</el-button>
            <el-button type="text">调岗</el-button>
            <el-button type="text">离职</el-button>
            <el-button type="text">角色</el-button>
            <el-button type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 使用弹框组件 -->
    <prccesspanel
      @updateData="getuserAllList"
      :dialogShow.sync="dialogShow"
    ></prccesspanel>
  </div>
</template>

<script>
import { getUserAllSimpleApi } from '@/api/emloyees'
export default {
  data () {
    return {
      // 员工列表数据源
      list: [{ name: 'xjj' }],
      // 当前页
      currentPage: 1,
      // 页容量的集合
      pageSizes: [2, 4, 6, 8],
      // 当前页容量
      pageSize: 2,
      // 总条数
      total: 0,
      //控制面板显示隐藏
      dialogShow: false
    }
  },
  methods: {
    // 获取所有的用户信息
    async getuserAllList () {
      const res = await getUserAllSimpleApi({
        page: this.currentPage,
        size: this.pageSize
      })
      //console.log(res)
      // 保存数据
      this.list = res.data.rows
      this.total = res.data.total
    },
    // 页容量改变时触发
    handleSizeChange (size) {
      this.pageSize = size
      this.getuserAllList()
    },
    // 当前页改变时触发
    handleCurrentChange (page) {
      this.currentPage = page
      this.getuserAllList()
    },
    //点击新增
    openAdd () {
      this.dialogShow = true
    }
  },
  created () {
    this.getuserAllList()
  },
  //导入新增面板组件
  components: {
    prccesspanel: () => import('./components/add.vue')
  }
}
</script>

<style lang="scss">
.employees {
  margin: 20px;
  .mycard {
    margin-top: 20px;
  }
  .el-table__header {
    th:last-child {
      .cell {
        text-align: center;
      }
    }
  }
}
</style>
